class Rectangle { private int length,breadth; public void area() { int a =length*breadth; System.out.println("Area is "+a); } public void setdimension(int m,int n) { length=m; breadth=n; } } class demo { public static void main(String args[]) { rectangle a,b; a=new rectangle(); b=new rectangle(); a.setdimension(5,7); b.setdimension(10,20); int z=a.area()+b.area(); System.out.println("Total area is"+z); System.out.println("Area of a is"+ a.area()); System.out.println("Area of b is"+ b.area()); } }
Total Area is 235 Area of a is 35 Area of b is 200
class Worker { private int wages,wdays; public int payment() { int p=wages*wdays; return p ; } public void setData(int w,int d) { wages=w; wdays=d; } } class demo { public static void main(String args[]) { Worker a,b; a=new Worker(); b=new Worker(); a.setData(500,5); b.setData(750,2); int z=a.payment()+b.payment(); System.out.println("Total Payment is "+z); } }
Total Payment is 4000